package com.weixin.project.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.weixin.project.Util.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class SearchService {
    @Value("${python.searchURL}")
    private String pythonURL;
    @Autowired
    HttpService httpService;
    public String imageOCR(String base64File){
        JSONObject requestBody = new JSONObject();
        requestBody.put("image", base64File);
        String url = pythonURL + "/WebAPI/PaddleOCR";
        JSONObject responseBody = httpService.sendPostRequest(url, requestBody);
        return responseBody.getString("text");
    }

    public JSONArray imageNLP(String text){
        JSONObject requestBody = new JSONObject();
        requestBody.put("text", text);
        String url = pythonURL + "/WebAPI/nlp";
        JSONObject responseBody = httpService.sendPostRequest(url, requestBody);
        return responseBody.getJSONArray("token");
    }
}
